//
//  RZQReplayTableViewCell.m
//  LastOne
//
//  Created by dllo on 15/11/9.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "RZQReplayTableViewCell.h"
#import "FitHeader.h"
#import "NightHeader.h"
#import <UIImageView+WebCache.h>
@implementation RZQReplayTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatAction];
        [self.contentView NightWithType:UIViewColorTypeNormal];
    }
    return self;
}
-(void)creatAction;
{
    _headImage = [[UIImageView alloc]init];
    [self.contentView addSubview:_headImage];
    _messageLabel = [[UILabel alloc]init];
     [self.contentView addSubview:_messageLabel];
    _nameLabel = [[UILabel alloc]init];
     [self.contentView addSubview:_nameLabel];
    _timeLabel = [[UILabel alloc]init];
     [self.contentView addSubview:_timeLabel];
    _zanImage = [[UIImageView alloc]init];
     [self.contentView addSubview:_zanImage];
    
    
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _headImage.frame  = CGRectMake(5 * FitWidth, 10 * FitHeight, 30 * FitWidth, 30 * FitHeight);
    _headImage.layer.cornerRadius = 15 ;
    _headImage.clipsToBounds = YES;
  
    _nameLabel.frame = CGRectMake(40 * FitWidth , 15 * FitHeight, 200 * FitWidth, 20 * FitHeight);
    
    _timeLabel.frame = CGRectMake(40 * FitWidth, _messageLabel.frame.origin.y + _messageLabel.frame.size.height + 10 * FitHeight, 200 * FitWidth, 20 * FitHeight);
    
    
    
}
-(void)setModelData:(RecommendModel *)modelData
{
    if (_modelData != modelData) {
        _modelData = modelData;
    }
   
    
    [_headImage sd_setImageWithURL:[NSURL URLWithString:[_modelData.author objectForKey:@"avatar"]]];
    _nameLabel.text = [_modelData.author objectForKey:@"name"];
     _nameLabel.font =  [UIFont fontWithName:@"Helvetica-Bold" size:18];
    [_nameLabel NightWithType:UIViewColorTypeNormal];
    _messageLabel.text = _modelData.content;
    _messageLabel.font =  [UIFont fontWithName:@"Helvetica-Bold" size:18];
    [_messageLabel NightWithType:UIViewColorTypeNormal];
    NSDate *date1 = [NSDate date];
  
    
    NSDate *detaildate = [[NSDate alloc]initWithTimeIntervalSince1970:_modelData.publish_time];
    NSTimeInterval interval = [date1 timeIntervalSinceDate:detaildate];
    
    if (interval < 60) {
        _timeLabel.text = @"刚刚";
    }
    else if (interval >= 60 && interval <= 3600)
    {
        _timeLabel.text = [NSString stringWithFormat:@"%ld分钟前", (long)interval / 60];
    }
    else if (interval >= 3600 && interval <= 3600 * 24 )
    {
        
         _timeLabel.text = [NSString stringWithFormat:@"%ld小时前",(long)interval / 3600];
     
    }
    else if (interval >= 3600 * 24 && interval <= 7200 * 24 )
    {
            NSDateFormatter *dateFormayyer = [[NSDateFormatter alloc]init];
            [dateFormayyer setDateFormat:@" HH:mm"];
        _timeLabel.text =[NSString stringWithFormat:@"昨天 %@", [dateFormayyer stringFromDate:detaildate]];
        
    }
    else
    {
        NSDateFormatter *dateFormayyer = [[NSDateFormatter alloc]init];
        [dateFormayyer setDateFormat:@"MM-dd HH:mm"];
        _timeLabel.text = [dateFormayyer stringFromDate:detaildate];
        
    }
    [_timeLabel NightWithType:UIViewColorTypeNormal];

    
    
}
-(void)setHigh:(CGFloat)high
{
    _high = high;
    _messageLabel.frame =  CGRectMake(40 * FitWidth, 50 * FitHeight, 300 * FitWidth, high * FitHeight);
    _messageLabel.numberOfLines = 0;
    [_messageLabel NightWithType: UIViewColorTypeNormal];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
